package leetcode.median;

public class $365_CanMeasureWater {
    public boolean canMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity) {
        if (jug1Capacity + jug2Capacity < targetCapacity) {
            return false;
        }
        int max = Math.max(jug1Capacity, jug2Capacity);
        int min = Math.min(jug1Capacity, jug2Capacity);
        int cur = max + min;
        while (cur > 0) {
            if (cur == targetCapacity) {
                return true;
            }
            if (cur >= min) {
                cur -= min;
            } else {
                cur += max;
            }
        }
        return false;
    }
}
